package com.example.backend.mapper;


import com.example.backend.entity.Admin;
import com.github.pagehelper.util.StringUtil;

import java.util.HashMap;

public class AdminMapperProvider {
    public String getUpdateAdminSql(Admin admin) {
    StringBuffer sql = new StringBuffer("update admin set id = #{id} ");
    if(StringUtil.isNotEmpty(admin.getName())){
        sql.append(" ,name = #{name} ");
    }
    if(StringUtil.isNotEmpty(admin.getPwd())){
        sql.append(" ,pwd = #{pwd} ");
    }
    if(StringUtil.isNotEmpty(admin.getRealname())){
        sql.append(" ,realname = #{realname} ");
    }

    sql.append(" where id = #{id}");
    return sql.toString();
}

    /**
     * 获取查询管理员的SQL
     * @param admin
     * @return sql
     */
    public String getSelectAdminsSql(Admin admin){
        StringBuffer sql = new StringBuffer("select * from admin where 1=1 ");
        if(StringUtil.isNotEmpty(admin.getName())){
            sql.append(" and name like concat('%',#{name},'%') ");
        }

        if(StringUtil.isNotEmpty(admin.getRealname())){
            sql.append(" and realname like concat('%',#{realname},'%') ");
        }

        return sql.toString();
    }

    public String getSelectAdminsByUser2Sql(HashMap<String,Admin> map){

        Admin admin1 = map.get("param1");
        Admin admin2 = map.get("param2");
        return "";
    }
}